<template>
  <c-dialog ref="dialog" :data="selData" single title="变更形象督导">
    <c-list ref="form" :model="formData" :rules="formRules" :column="1" label-width="120px">
      <c-list-item label="软装陈列任务号" :value="detail.softwearTaskCode" />
      <c-list-item label="所属门店" :value="detail.shopName" />
      <c-list-item label="装修任务号" :value="detail.decorationTaskCode" />
      <c-list-item label="变更前形象督导" :value="detail.formSupervisorName" />
      <c-list-item label="变更后形象督导" prop="formSupervisorCode">
        <c-single-dialog
          ref="formSupervisorCode"
          v-model="formData.formSupervisorCode"
          :label.sync="formData.formSupervisorName"
          :props="{label:'userName',value:'account'}"
          :focus-query="true"
          :multiple="false"
          :config="{
            title:'变更后形象督导',
            width:'600px',
            interfacePath:`/slm-admin/api/v1/user/listUsers`,
            method:'post',
            filtersRaw:filtersRaw,
            paramsRaw:{},
            setting:[
              {prop:'account',title:'编码',width:80},
              {prop:'userName',title:'名字',width:150},
              {prop: 'phone', title: '电话', width: 150}
            ]
          }"
          @change="changeData"
        />
      </c-list-item>
      <c-list-item label="变更后形象督导部门">
        {{ orgInfo }}
      </c-list-item>
    </c-list>
    <div class="btn-container">
      <c-button @click="cancelHandle">取消</c-button>
      <c-button type="primary" @click="confirmHandle">确认</c-button>
    </div>
  </c-dialog>
</template>
<script>
import { postChangeSupervisor } from '@/api/softDecorate'
import { otherFiltersItem } from '@/utils'
import { getOrgByAccount } from '@/api/common'

export default {
  name: 'Visualize',
  props: {
    selData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      orgInfo: '',
      formData: {
        formSupervisorCode: '',
        formSupervisorName: ''
      },
      formRules: {
        formSupervisorCode: [{ required: true, message: '请选择形象督导', trigger: 'change' }]
      }
    }
  },
  computed: {
    detail() {
      return this.selData.length > 0 ? this.selData[0] : {}
    },
    filtersRaw() {
      if (this.detail.formSupervisorCode) {
        return [
          otherFiltersItem('account', this.detail.formSupervisorCode, '<>')
        ]
      }
      return []
    }
  },
  methods: {
    changeData(data) {
      getOrgByAccount(data.account).then(res => {
        if (res.success === 1) {
          if (res.data.length !== 0) {
            const list = res.data.map(el => el.orgName)
            this.orgInfo = list.join(',')
          } else {
            this.orgInfo = ''
          }
        }
      })
    },
    confirmHandle() {
      this.$refs.form.validate().then(() => {
        this.$gsec('EXCEPT024').then(([cfg, ecd]) => {
          const d = this.detail
          ecd.constCode = d.constCode
          ecd.bizCode = d.decorationTaskCode
          ecd.modelId = d.id
          const t = this.$gsed()
          // t.belongDuty = d.belongDuty || ''
          t.remark = ''
          ecd.shopExceptionDetailDTOS = [t]
          const data = {
            exceptionDTO: ecd,
            id: d.id,
            ...this.formData,
            decorationTaskCode: d.decorationTaskCode
          }
          postChangeSupervisor(data).then(res => {
            this.$message.success('操作成功！')
            this.$emit('on-success')
            this.$refs.dialog.visible = false
          })
        })
      })
    },
    cancelHandle() {
      this.$refs.dialog.visible = false
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
